from alipay import AliPay, DCAliPay, ISVAliPay
from alipay.utils import AliPayConfig

app_private_key_string = open("keys/app_private_key.pem").read()
alipay_public_key_string = open("keys/alipay_public_key.pem").read()

# app_private_key_string == """
#     -----BEGIN RSA PRIVATE KEY-----
#     base64 encoded content
#     -----END RSA PRIVATE KEY-----
# """
#
# alipay_public_key_string == """
#     -----BEGIN PUBLIC KEY-----
#     base64 encoded content
#     -----END PUBLIC KEY-----
# """

alipay = AliPay(
    appid="2016080100142469",
    app_notify_url=None,  # 后台通知地址
    app_private_key_string=app_private_key_string,
    # 支付宝的公钥，验证支付宝回传消息使用，不是你自己的公钥,
    alipay_public_key_string=alipay_public_key_string,
    sign_type="RSA2", # RSA 或者 RSA2
    debug=True,  # 默认False
)

# 如果你是 Python 3的用户，使用默认的字符串即可
subject = "测试订单"

# 电脑网站支付，需要跳转到https://openapi.alipay.com/gateway.do? + order_string
order_string = alipay.api_alipay_trade_page_pay(
    out_trade_no="20161112",  # syl订单号
    total_amount=0.01,  # 金额
    subject=subject,  # 商品名
    return_url="http://127.0.0.1:8080/payment/callback/",
)

# print(order_string)
"""   生成传递的参数
app_id=2016080100142469&biz_content=%7B%22subject%22%3A%22%5Cu6d4b%5Cu8bd5%5Cu8ba2%5Cu5355%22%2C%22out_trade_no%22%3A%2220161112%22%2C%22total_amount%22%3A0.01%2C%22product_code%22%3A%22FAST_INSTANT_TRADE_PAY%22%7D&charset=utf-8&method=alipay.trade.page.pay&return_url=http%3A%2F%2F127.0.0.1%3A8080%2Fpayment%2Fcallback%2F&sign_type=RSA2&timestamp=2020-12-05+15%3A19%3A25&version=1.0&sign=PPjrXf3QA70Ik17Ux2owlu37jPa6IByGapbeZKrImcKDWPJtto8cjXYUiGHJWnv9JoH6NRGGK7BPZJWALlRD1K%2Bbv8ZcHV9GPiOOhccnvsaXrLoHRJqp65Rf49eMExGKaok2SKDx1DZ%2FDJP8nciPqu44JIz2BWaPKCews%2B36PN9Bs6wX%2FgIPsac4V%2BH9ZXFCBhnr5%2FePwmhdZ1MI1IOd3AuuqdBgmW%2F9aqFnpcurZpHpURgCLs%2FedrDRSW5jDp6DQ5ReWeelDYYK8FE3U2QNRD3VYtWvVm6wqq%2BYNnV2MEpetNjnT%2F5FR1opDGSkXCg6mMEiIqrxTgeAKL674r1Pig%3D%3D
"""
base_url = 'https://openapi.alipaydev.com/gateway.do?'
pay_url = base_url+order_string
print(pay_url)



"""
http://127.0.0.1:8080/payment/callback/?
charset=utf-8
&out_trade_no=20161112  # syl订单号
&method=alipay.trade.page.pay.return
&total_amount=0.01  # 总金额
&trade_no=2020120522001494010500875686  # 支付宝交易号
&auth_app_id=2016080100142469  # appid  商家的id
&version=1.0  # 
&app_id=2016080100142469  # appid  商家id
&sign_type=RSA2  # 签名方式
&seller_id=2088102169475485  # 商家id
&timestamp=2020-12-05%2015%3A23%3A07   # 交易时间
"""
"""
&sign=LuC3rWjoYQf2HRyzaXS6cPfz4LrqO%2BPNcHw3n1TyCDM6nmfkg8gki0rkdD5DM1ADsE2d%2BR4Z1G%2BUclTH2Jj48np0S%2By14gr30CL30zvPKmFS4nSx5M1sL5jEw2AscIbN6WdpyH0%2By2EVMcUvFyeuJ9uJgWAhPnavrjPVFre9iGQeSNYGjJIwkWe7QJj97To%2FFFgSp6kzKnwVnq%2Bg9Lc5EtWBgXW%2B%2Fk2%2FEY18OG%2F71ZpFzT2wUrUrrywhfyDzhvU1qBpO39SJr8ARHx5KT0m2EQAeAvcurjctJfbi%2FcFlRTTh3%2FpnJ%2BafAC1gbv90V5SF0tHBTo4T%2B15%2B17IvJRfQPQ%3D%3D
"""